package org.langqiao.thread;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class TraditionalTimerTest {
	static int count =0;
	public static void main(String[] args) {
		class MyTimerTask extends TimerTask{
			@Override
			public void run() {
				count++;
				System.out.println("11111111111");
				new Timer().schedule(new MyTimerTask(), 2000+(count %2)*2000);
			}
			
		}
		new Timer().schedule(new MyTimerTask(), 2000);
		/*new Timer().schedule(new TimerTask() {
			
			@Override
			public void run() {
				System.out.println("11111111111"); 
				new Timer().schedule(new TimerTask() {
					
					@Override
					public void run() {
						System.out.println("22222222");
					}
				}this, 2000);
			}
		}, 2000);*/
		while(true){
			System.out.println(new Date().getSeconds());
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
